﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using SHJunketingBLL;
using SHJunketingModel;
using Web;
using System.Data;
using System.Collections.Generic;


public partial class Admin_UserManagement_userManageEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            IList<C_YuyueType> list = C_YuyueTypeManage.GetAllC_YuyueType();

            this.ddlYuyuefenlei.Items.Clear();
            //this.ddlYuyuefenlei.Items.Add(new ListItem("请选择所属类别...", ""));

            foreach (C_YuyueType dr in list)
            {

                this.ddlYuyuefenlei.Items.Add(new ListItem(dr.Name, dr.ID.ToString()));
            }
            ddlYuyuefenlei.SelectedIndex = 0;

            this.lblTime.Text = list[0].Starttime + "/" + list[0].Endtime;

           
            if (Request.QueryString["userId"] != null)
            {
                int userId = Convert.ToInt32(Request.QueryString["userId"]);
                //查询出用户
                string sql = "select * from users where userid = " + userId;

                DataTable table = DBHelper.GetDataSet(sql);

                if (table.Rows.Count > 0)
                {
                    this.txtName.Text = table.Rows[0]["userlogin"].ToString();
                    txtUserName.Text = table.Rows[0]["UserName"].ToString();
                    rdoSex.SelectedValue = table.Rows[0]["UserSex"].ToString();
                    txtDepartment.Text = table.Rows[0]["Department"].ToString();
                    txtCostCenters.Text = table.Rows[0]["CostCenters"].ToString();
                    txtUserIDCard.Text = table.Rows[0]["UserIDCard"].ToString();
                    txtUserAge.Text = table.Rows[0]["UserAge"].ToString();
                    rdoMarriage.SelectedValue = table.Rows[0]["Marriage"].ToString();
                    txtPhoneNumber.Text = table.Rows[0]["HandsetNumber"].ToString();
                    txtTelephone.Text = table.Rows[0]["TelephoneNumber"].ToString();
                    txtAddress.Text = table.Rows[0]["UserAddress"].ToString();
                    txtUserEmai.Text = table.Rows[0]["UserEmail"].ToString();
                    txtArea.Text = table.Rows[0]["Area"].ToString();
                    rdoLang.SelectedValue = table.Rows[0]["language"].ToString();
                    rdoVIP.SelectedValue = table.Rows[0]["whetherVIP"].ToString();
                    rdoUser.SelectedValue = table.Rows[0]["whetherUser"].ToString();
                    txtRemark.Text = table.Rows[0]["userRemark"].ToString();

                    ViewState["userId"] = table.Rows[0]["UserId"];
                    ddlYuyuefenlei.SelectedValue = table.Rows[0]["yuyuefenleiid"].ToString();
                }

                if (ddlYuyuefenlei.SelectedValue != "")
                {
                    C_YuyueType YuyueType = C_YuyueTypeManage.GetYuyueTypeByID(int.Parse(ddlYuyuefenlei.SelectedValue));
                    this.lblTime.Text = YuyueType.Starttime + "/" + YuyueType.Endtime;
                }
            }
        }
    }
    protected void btnEbit_Click(object sender, EventArgs e)
    {
        string sql =
                 "UPDATE users " +
                 "SET " +
                     "UserLogin = '" + txtName.Text.Trim() + "', " +
                     "UserName = '" + txtUserName.Text.Trim() + "'," +
                     "UserSex = '" + rdoSex.SelectedValue + "'," +
                     "Department = '" + txtDepartment.Text.Trim() + "'," +
                     "CostCenters  = '" + txtCostCenters.Text.Trim() + "'," +
                     "UserIDCard = '" + txtUserIDCard.Text.Trim() + "'," +
                     "UserAge = '" + txtUserAge.Text.Trim() + "'," +
                     "Marriage  = '" + rdoMarriage.SelectedValue + "'," +
                     "HandsetNumber = '" + txtPhoneNumber.Text.Trim() + "'," +
                     "TelephoneNumber = '" + txtTelephone.Text.Trim() + "'," +
                     "UserAddress = '" + txtAddress.Text.Trim() + "'," +
                     "UserEmail = '" + txtUserEmai.Text.Trim() + "'," +
                     "Area  = '" + txtArea.Text.Trim() + "'," +
                     "whetherUser  = '" + rdoUser.SelectedValue + "'," +
                     "whetherVIP  = '" + rdoVIP.SelectedValue + "'," +
                     "userRemark  = '" + txtRemark.Text.Trim() + "'," +
                     "yuyuefenleiid  = " + int.Parse(ddlYuyuefenlei.SelectedValue) + "," +
                     
                     "language  = '" + rdoLang.SelectedValue + "'" +

                 "WHERE UserID = '" + ViewState["userId"].ToString() + "'";

        int result = DBHelper.ExecuteCommand(sql);
        if (result > 0)
        {
            Web.CommFun.Show_Msg("修改成功！", "userManage.aspx");
        }
        else
        {
            Web.CommFun.Show_Msg("修改失败！", "userManage.aspx");
        }
    }
    //重置密码
    protected void Button1_Click(object sender, EventArgs e)
    {
        string sql =
                 "UPDATE users " +
                 "SET " +
                     "UserPwd  = '666666'" +

                 "WHERE UserID = '" + ViewState["userId"].ToString() + "'";
        int result = DBHelper.ExecuteCommand(sql);
        if (result > 0)
        {
            Web.CommFun.Show_Msg("重置密码成功！");
        }
        else
        {
            Web.CommFun.Show_Msg("重置密码失败！");
        }
    }

    protected void ddlYuyuefenlei_SelectedIndexChanged(object sender, EventArgs e)
    {

        if (ddlYuyuefenlei.SelectedValue == "")
        {
            return;
        }
        C_YuyueType type = C_YuyueTypeManage.GetYuyueTypeByID(int.Parse(ddlYuyuefenlei.SelectedValue));
        this.lblTime.Text = type.Starttime + "/" + type.Endtime;
    }
}
